{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from keras.models import Model\n",
    "from keras.layers import Input\n",
    "from keras.layers.recurrent import SimpleRNN, LSTM, GRU\n",
    "from keras.layers.wrappers import Bidirectional\n",
    "from keras import backend as K\n",
    "import json\n",
    "from collections import OrderedDict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def format_decimal(arr, places=6):\n",
    "    return [round(x * 10**places) / 10**places for x in arr]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "DATA = OrderedDict()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bidirectional"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.0] merge_mode='sum', wrap a SimpleRNN layer with units=4, activation='tanh', return_sequences=False**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 4)\n",
      "W: [0.317596, 0.688515, -0.688309, -0.48247, 0.387223, -0.718263, 0.281673, -0.106311, 0.576861, -0.083926, 0.631691, 0.92647, 0.579655, -0.024215, -0.805793, -0.842947, -0.955415, 0.656415, 0.44667, 0.633739, 0.701525, 0.917507, -0.185671, -0.105247]\n",
      "U shape: (4, 4)\n",
      "U: [-0.332867, 0.650317, 0.995501, -0.458367, -0.30351, 0.37881, -0.248093, 0.372204, -0.698964, -0.408058, -0.103801, 0.376217, -0.724015, 0.708616, -0.513219, -0.46074]\n",
      "b shape: (4,)\n",
      "b: [-0.018116, 0.65912, 0.769708, 0.313803]\n",
      "W shape: (6, 4)\n",
      "W: [0.09181, 0.603458, -0.605956, 0.484425, 0.510238, 0.846944, 0.889925, -0.786016, 0.813665, -0.811729, 0.536095, -0.174245, 0.368024, 0.683977, -0.857333, -0.005531, 0.781397, 0.512491, 0.340635, -0.819093, -0.778165, 0.427181, -0.392763, -0.720549]\n",
      "U shape: (4, 4)\n",
      "U: [-0.702767, -0.818005, 0.960855, -0.340243, -0.149024, 0.664644, 0.32663, -0.888726, 0.992616, 0.574741, 0.384116, -0.872589, 0.903384, -0.816145, -0.931977, 0.03192]\n",
      "b shape: (4,)\n",
      "b: [0.469998, 0.339932, -0.133694, -0.467748]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [-0.858898, -0.8339, 0.259565, -0.018129, 0.333949, 0.848107, 0.96387, 0.349427, -0.554177, -0.032331, 0.139825, 0.079569, -0.88255, -0.692016, 0.332476, -0.125685, 0.614931, -0.036786]\n",
      "out shape: (4,)\n",
      "out: [-0.19343, 1.34031, 0.608347, -0.003095]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(SimpleRNN(4, activation='tanh', return_sequences=False), merge_mode='sum')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4000 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.0'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.1] merge_mode='mul', wrap a SimpleRNN layer with units=4, activation='tanh', return_sequences=False**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 4)\n",
      "W: [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397]\n",
      "U shape: (4, 4)\n",
      "U: [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973]\n",
      "b shape: (4,)\n",
      "b: [0.653857, -0.422921, -0.769865, 0.386656]\n",
      "W shape: (6, 4)\n",
      "W: [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342]\n",
      "U shape: (4, 4)\n",
      "U: [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679]\n",
      "b shape: (4,)\n",
      "b: [-0.095243, 0.193295, -0.158108, -0.236503]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829]\n",
      "out shape: (4,)\n",
      "out: [0.258819, -0.529755, 0.723585, -0.131471]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(SimpleRNN(4, activation='tanh', return_sequences=False), merge_mode='mul')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4010 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.1'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.2] merge_mode='concat', wrap a SimpleRNN layer with units=4, activation='tanh', return_sequences=False**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 4)\n",
      "W: [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397]\n",
      "U shape: (4, 4)\n",
      "U: [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973]\n",
      "b shape: (4,)\n",
      "b: [0.653857, -0.422921, -0.769865, 0.386656]\n",
      "W shape: (6, 4)\n",
      "W: [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342]\n",
      "U shape: (4, 4)\n",
      "U: [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679]\n",
      "b shape: (4,)\n",
      "b: [-0.095243, 0.193295, -0.158108, -0.236503]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829]\n",
      "out shape: (8,)\n",
      "out: [0.982344, -0.537111, -0.869863, -0.839838, 0.26347, 0.986305, -0.831838, 0.156544]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(SimpleRNN(4, activation='tanh', return_sequences=False), merge_mode='concat')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4010 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.2'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.3] merge_mode='ave', wrap a SimpleRNN layer with units=4, activation='tanh', return_sequences=False**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 4)\n",
      "W: [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397]\n",
      "U shape: (4, 4)\n",
      "U: [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973]\n",
      "b shape: (4,)\n",
      "b: [0.653857, -0.422921, -0.769865, 0.386656]\n",
      "W shape: (6, 4)\n",
      "W: [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342]\n",
      "U shape: (4, 4)\n",
      "U: [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679]\n",
      "b shape: (4,)\n",
      "b: [-0.095243, 0.193295, -0.158108, -0.236503]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829]\n",
      "out shape: (4,)\n",
      "out: [0.622907, 0.224597, -0.85085, -0.341647]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(SimpleRNN(4, activation='tanh', return_sequences=False), merge_mode='ave')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4010 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.3'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.4] merge_mode='concat', wrap a SimpleRNN layer with units=4, activation='tanh', return_sequences=True**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 4)\n",
      "W: [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397]\n",
      "U shape: (4, 4)\n",
      "U: [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973]\n",
      "b shape: (4,)\n",
      "b: [0.653857, -0.422921, -0.769865, 0.386656]\n",
      "W shape: (6, 4)\n",
      "W: [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342]\n",
      "U shape: (4, 4)\n",
      "U: [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679]\n",
      "b shape: (4,)\n",
      "b: [-0.095243, 0.193295, -0.158108, -0.236503]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829]\n",
      "out shape: (3, 8)\n",
      "out: [0.896581, -0.954891, -0.158707, 0.372146, 0.26347, 0.986305, -0.831838, 0.156544, 0.990187, -0.957637, -0.916605, -0.917549, 0.365499, 0.974113, -0.934135, -0.105309, 0.982344, -0.537111, -0.869863, -0.839838, -0.759049, 0.61521, -0.756189, 0.055226]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(SimpleRNN(4, activation='tanh', return_sequences=True), merge_mode='concat')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4010 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.4'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.5] merge_mode='concat', wrap a GRU layer with units=4, activation='tanh', recurrent_activation='hard_sigmoid', return_sequences=True**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 12)\n",
      "W: [-0.400676, -0.806051, 0.727377, 0.299105, 0.162793, 0.696317, -0.630284, 0.653073, 0.242925, 0.148925, -0.187914, 0.351016, 0.546924, 0.075698, -0.743714, 0.635785, -0.867496, -0.475611, -0.836474, -0.099114, 0.730422, -0.75379, 0.737732, -0.042137, 0.648025, -0.050435, -0.231487, 0.332196, 0.529451, -0.350969, -0.287331, -0.108567, 0.290426, -0.498405, -0.986393, 0.140917, -0.18627, -0.278213, -0.28632, 0.342007, -0.711494, 0.26935, 0.769428, -0.817747, 0.65287, -0.242099, -0.155553, -0.463521, 0.019267, -0.511599, 0.208023, 0.140939, 0.609705, -0.970713, -0.812048, 0.603712, 0.440668, -0.967074, 0.876051, 0.675455, 0.333284, 0.618455, 0.468442, 0.671832, -0.605946, -0.917533, 0.270426, -0.426635, 0.341593, 0.837614, -0.175833, -0.465587]\n",
      "U shape: (4, 12)\n",
      "U: [-0.045344, -0.164038, -0.268339, 0.845397, -0.243892, 0.889969, -0.723107, -0.812532, -0.162915, 0.054766, 0.995428, 0.904954, -0.227887, -0.717716, 0.369742, 0.764909, 0.43452, -0.100535, 0.253479, 0.195278, 0.984495, -0.595437, 0.928364, -0.088226, -0.297404, -0.38593, 0.051969, -0.206956, 0.92133, -0.573615, 0.753414, -0.820892, 0.768965, 0.831183, -0.083506, -0.806636, -0.822986, -0.266864, -0.738629, 0.655838, -0.908376, -0.832082, 0.125397, 0.231704, -0.141658, 0.324014, 0.090288, -0.306376]\n",
      "b shape: (12,)\n",
      "b: [-0.034764, 0.373026, 0.5397, 0.050508, 0.828587, 0.724982, 0.888847, 0.267944, 0.976953, -0.776123, -0.387651, -0.192234]\n",
      "W shape: (6, 12)\n",
      "W: [-0.48369, -0.447759, -0.566219, 0.343364, -0.24531, 0.701212, 0.035146, 0.441802, 0.667955, -0.504994, 0.666803, -0.831937, 0.197281, -0.417857, -0.39006, 0.86274, 0.715555, -0.617149, 0.333407, 0.642035, -0.919191, -0.828808, -0.477502, -0.727975, -0.999427, 0.0147, 0.861423, 0.587883, 0.980264, -0.295717, 0.048024, -0.025603, 0.062474, -0.54466, -0.593996, -0.515015, -0.17945, -0.035334, 0.418348, -0.276447, 0.911704, -0.965374, -0.912856, 0.559908, -0.423473, -0.554133, -0.319797, -0.849149, 0.969828, -0.634512, 0.268302, -0.737053, -0.538017, -0.480322, -0.361186, 0.318054, -0.852645, -0.519945, 0.499858, 0.073199, -0.093714, -0.172873, -0.927642, 0.042101, -0.419142, 0.922898, -0.709046, -0.454268, 0.884395, -0.725468, -0.50797, -0.683535]\n",
      "U shape: (4, 12)\n",
      "U: [-0.306533, -0.235389, -0.903843, -0.310018, -0.211702, -0.929241, -0.211704, -0.855145, 0.244396, 0.334903, 0.219381, 0.938061, -0.013659, 0.841669, 0.063987, -0.822806, -0.950197, 0.756071, 0.796209, 0.139445, -0.468052, 0.548326, 0.580119, -0.818757, -0.382378, -0.374014, 0.415244, -0.913233, -0.21266, 0.745815, -0.707557, 0.541733, -0.726652, 0.669064, -0.696091, 0.21855, 0.638637, -0.970069, 0.709007, 0.151012, -0.164932, -0.394785, 0.590232, -0.956107, 0.252234, 0.092064, 0.676041, 0.326743]\n",
      "b shape: (12,)\n",
      "b: [-0.064656, -0.046499, -0.690927, -0.559937, -0.676503, -0.827929, -0.488517, 0.039733, 0.473848, 0.938037, 0.999271, -0.961714]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [0.579459, -0.589792, -0.267425, 0.603619, 0.96337, -0.768615, 0.684727, -0.085752, 0.631217, -0.536656, -0.354471, 0.293334, -0.840082, 0.990845, 0.28264, 0.692538, 0.965158, 0.451587]\n",
      "out shape: (3, 8)\n",
      "out: [0.594504, -0.714787, 0.058666, 0.362111, 0.113399, 0.386766, 0.769737, -0.644836, 0.43217, -0.360749, -0.335977, 0.33945, 0.728847, -0.092921, 0.368333, -0.71776, 0.602782, -0.557467, 0.453357, 0.247038, -0.276008, -0.447068, -0.092065, -0.617043]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(GRU(4, activation='tanh', recurrent_activation='hard_sigmoid', return_sequences=True), merge_mode='concat')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4020 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.5'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**[wrappers.Bidirectional.6] merge_mode='concat', wrap a LSTM layer with units=4, activation='tanh', recurrent_activation='hard_sigmoid', return_sequences=True**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weights are for forward layer + backward layer\n",
      "W shape: (6, 16)\n",
      "W: [0.807118, -0.760589, -0.028865, -0.670325, -0.896482, -0.750147, 0.736501, 0.743636, 0.608933, 0.703828, 0.161015, 0.851966, -0.268783, -0.04837, 0.236778, -0.886123, 0.813034, -0.380336, -0.214975, -0.8337, -0.536234, 0.415819, -0.469715, -0.501354, -0.612303, 0.999023, -0.131152, -0.659838, -0.969144, 0.658844, -0.060329, -0.484303, -0.280648, 0.158796, 0.324335, -0.583718, 0.05907, 0.085148, -0.159317, 0.832273, 0.008118, -0.179334, -0.641468, 0.049695, -0.898869, 0.887157, 0.940259, -0.799015, -0.657864, 0.263749, -0.466117, 0.454708, -0.256237, 0.069986, -0.084429, 0.153432, 0.467724, 0.614946, 0.8988, 0.903929, -0.04614, 0.605232, 0.352153, -0.589127, -0.893261, 0.626536, 0.69489, 0.032637, -0.058497, -0.869516, -0.089778, 0.563949, 0.608511, -0.279182, 0.240354, 0.20926, 0.265094, 0.144285, 0.480487, 0.036267, -0.313521, -0.075342, 0.162992, 0.039256, 0.277475, -0.777398, 0.385225, 0.548992, 0.434589, -0.029444, -0.697455, -0.93891, -0.766289, -0.892662, -0.759472, 0.359897]\n",
      "U shape: (4, 16)\n",
      "U: [0.33535, -0.58156, -0.54846, 0.092896, -0.282469, -0.433627, 0.649036, -0.167267, 0.228306, -0.410728, 0.057924, 0.779121, 0.002282, -0.056874, 0.501906, 0.237949, 0.855971, 0.945186, 0.37607, -0.434584, 0.293534, 0.0914, -0.889186, 0.87441, 0.645452, -0.306185, -0.676605, 0.233388, -0.261631, -0.984845, 0.766819, -0.867325, -0.879335, 0.317177, -0.95397, -0.506246, -0.906304, -0.34783, 0.332394, -0.876325, 0.689498, 0.735502, -0.369079, 0.416847, -0.005394, -0.091598, -0.032022, 0.158824, -0.679499, -0.147576, -0.084029, 0.921847, -0.544815, -0.311653, -0.334702, 0.40131, -0.912162, 0.884366, -0.591035, -0.927795, 0.542396, -0.524613, -0.525259, 0.458834]\n",
      "b shape: (16,)\n",
      "b: [0.245776, 0.935485, 0.309313, 0.905204, 0.031089, 0.984402, 0.656903, -0.075944, -0.485436, -0.00131, 0.490612, 0.364067, -0.80787, -0.18118, -0.800993, 0.470466]\n",
      "W shape: (6, 16)\n",
      "W: [0.608142, 0.031424, -0.113381, 0.761242, 0.350692, 0.55033, -0.465194, -0.192457, 0.472623, 0.115715, -0.887, 0.253264, -0.180434, -0.840145, -0.86505, -0.017223, 0.472874, 0.895249, 0.798031, 0.285864, 0.661202, 0.990973, 0.628736, 0.077497, -0.669397, -0.026501, 0.158669, -0.779973, 0.798492, 0.543891, 0.847622, -0.127898, -0.900805, 0.89186, 0.025119, -0.19005, -0.959915, 0.63755, -0.970897, 0.375914, -0.641188, -0.681191, 0.111849, -0.171632, -0.171887, -0.265957, 0.936405, 0.14059, 0.571594, -0.761868, 0.368138, -0.995003, -0.624834, 0.263911, -0.335803, 0.524822, 0.768229, 0.213674, 0.51678, 0.448993, -0.681158, 0.515448, -0.375105, 0.77563, 0.681558, -0.832669, 0.432138, -0.866504, -0.069609, -0.427233, -0.455544, -0.708099, -0.211247, -0.060945, -0.431296, -0.406991, 0.184405, -0.940906, -0.074347, 0.89056, 0.470936, -0.912834, -0.31047, 0.32027, 0.902325, 0.826502, 0.749141, 0.997955, 0.679228, 0.057812, -0.46663, 0.902338, 0.667435, -0.17336, 0.924087, 0.399279]\n",
      "U shape: (4, 16)\n",
      "U: [-0.274857, -0.894091, 0.79009, 0.858528, -0.618948, 0.516904, 0.970979, 0.394163, 0.477123, -0.25245, 0.562477, -0.85766, -0.854637, 0.57802, -0.819807, -0.218625, 0.325063, -0.543383, 0.260624, 0.339218, 0.197457, 0.313392, -0.757072, 0.463311, -0.595705, 0.333942, -0.86221, 0.346486, -0.358319, 0.612121, -0.891709, -0.751211, -0.940398, 0.833448, -0.113211, 0.425797, 0.8656, 0.1088, 0.788351, 0.078212, 0.280996, 0.890594, -0.670749, -0.157674, -0.097224, 0.28997, -0.887052, 0.952481, -0.883093, -0.212071, 0.302231, -0.581727, 0.877721, 0.10562, 0.268526, 0.335971, -0.048939, -0.442724, 0.058181, -0.647222, 0.655541, -0.710984, 0.162741, -0.91302]\n",
      "b shape: (16,)\n",
      "b: [0.074086, 0.934899, -0.863756, 0.656665, -0.286312, -0.850001, 0.249795, -0.610878, 0.523095, -0.399227, 0.840477, -0.834731, 0.878922, -0.914947, 0.646411, 0.568749]\n",
      "\n",
      "in shape: (3, 6)\n",
      "in: [-0.208593, -0.791925, 0.482012, -0.811503, 0.611931, -0.69639, -0.087624, 0.563664, -0.730199, 0.739224, 0.349534, 0.409244, -0.160169, 0.084091, -0.337315, -0.358966, 0.984383, -0.783392]\n",
      "out shape: (3, 8)\n",
      "out: [-0.09132, -0.320823, 0.063094, 0.294734, 0.009347, -0.075279, 0.13049, -0.391936, -0.092975, 0.049853, 0.054893, 0.027423, 0.423312, 0.05639, 0.280809, -0.298506, -0.19041, -0.11039, 0.294735, 0.26807, -0.152633, -0.041449, 0.127926, -0.285122]\n"
     ]
    }
   ],
   "source": [
    "data_in_shape = (3, 6)\n",
    "\n",
    "layer_0 = Input(shape=data_in_shape)\n",
    "layer_1 = Bidirectional(LSTM(4, activation='tanh', recurrent_activation='hard_sigmoid', return_sequences=True), merge_mode='concat')(layer_0)\n",
    "model = Model(inputs=layer_0, outputs=layer_1)\n",
    "\n",
    "# set weights to random (use seed for reproducibility)\n",
    "weights = []\n",
    "for i, w in enumerate(model.get_weights()):\n",
    "    np.random.seed(4030 + i)\n",
    "    weights.append(2 * np.random.random(w.shape) - 1)\n",
    "model.set_weights(weights)\n",
    "weight_names = ['W', 'U', 'b', 'W', 'U', 'b']\n",
    "print('weights are for forward layer + backward layer')\n",
    "for w_i, w_name in enumerate(weight_names):\n",
    "    print('{} shape:'.format(w_name), weights[w_i].shape)\n",
    "    print('{}:'.format(w_name), format_decimal(weights[w_i].ravel().tolist()))\n",
    "\n",
    "data_in = 2 * np.random.random(data_in_shape) - 1\n",
    "result = model.predict(np.array([data_in]))\n",
    "data_out_shape = result[0].shape\n",
    "data_in_formatted = format_decimal(data_in.ravel().tolist())\n",
    "data_out_formatted = format_decimal(result[0].ravel().tolist())\n",
    "print('')\n",
    "print('in shape:', data_in_shape)\n",
    "print('in:', data_in_formatted)\n",
    "print('out shape:', data_out_shape)\n",
    "print('out:', data_out_formatted)\n",
    "\n",
    "DATA['wrappers.Bidirectional.6'] = {\n",
    "    'input': {'data': data_in_formatted, 'shape': data_in_shape},\n",
    "    'weights': [{'data': format_decimal(w.ravel().tolist()), 'shape': w.shape} for w in weights],\n",
    "    'expected': {'data': data_out_formatted, 'shape': data_out_shape}\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### export for Keras.js tests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"wrappers.Bidirectional.0\": {\"input\": {\"data\": [-0.858898, -0.8339, 0.259565, -0.018129, 0.333949, 0.848107, 0.96387, 0.349427, -0.554177, -0.032331, 0.139825, 0.079569, -0.88255, -0.692016, 0.332476, -0.125685, 0.614931, -0.036786], \"shape\": [3, 6]}, \"expected\": {\"data\": [-0.19343, 1.34031, 0.608347, -0.003095], \"shape\": [4]}, \"weights\": [{\"data\": [0.317596, 0.688515, -0.688309, -0.48247, 0.387223, -0.718263, 0.281673, -0.106311, 0.576861, -0.083926, 0.631691, 0.92647, 0.579655, -0.024215, -0.805793, -0.842947, -0.955415, 0.656415, 0.44667, 0.633739, 0.701525, 0.917507, -0.185671, -0.105247], \"shape\": [6, 4]}, {\"data\": [-0.332867, 0.650317, 0.995501, -0.458367, -0.30351, 0.37881, -0.248093, 0.372204, -0.698964, -0.408058, -0.103801, 0.376217, -0.724015, 0.708616, -0.513219, -0.46074], \"shape\": [4, 4]}, {\"data\": [-0.018116, 0.65912, 0.769708, 0.313803], \"shape\": [4]}, {\"data\": [0.09181, 0.603458, -0.605956, 0.484425, 0.510238, 0.846944, 0.889925, -0.786016, 0.813665, -0.811729, 0.536095, -0.174245, 0.368024, 0.683977, -0.857333, -0.005531, 0.781397, 0.512491, 0.340635, -0.819093, -0.778165, 0.427181, -0.392763, -0.720549], \"shape\": [6, 4]}, {\"data\": [-0.702767, -0.818005, 0.960855, -0.340243, -0.149024, 0.664644, 0.32663, -0.888726, 0.992616, 0.574741, 0.384116, -0.872589, 0.903384, -0.816145, -0.931977, 0.03192], \"shape\": [4, 4]}, {\"data\": [0.469998, 0.339932, -0.133694, -0.467748], \"shape\": [4]}]}, \"wrappers.Bidirectional.1\": {\"input\": {\"data\": [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829], \"shape\": [3, 6]}, \"expected\": {\"data\": [0.258819, -0.529755, 0.723585, -0.131471], \"shape\": [4]}, \"weights\": [{\"data\": [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397], \"shape\": [6, 4]}, {\"data\": [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973], \"shape\": [4, 4]}, {\"data\": [0.653857, -0.422921, -0.769865, 0.386656], \"shape\": [4]}, {\"data\": [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342], \"shape\": [6, 4]}, {\"data\": [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679], \"shape\": [4, 4]}, {\"data\": [-0.095243, 0.193295, -0.158108, -0.236503], \"shape\": [4]}]}, \"wrappers.Bidirectional.2\": {\"input\": {\"data\": [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829], \"shape\": [3, 6]}, \"expected\": {\"data\": [0.982344, -0.537111, -0.869863, -0.839838, 0.26347, 0.986305, -0.831838, 0.156544], \"shape\": [8]}, \"weights\": [{\"data\": [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397], \"shape\": [6, 4]}, {\"data\": [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973], \"shape\": [4, 4]}, {\"data\": [0.653857, -0.422921, -0.769865, 0.386656], \"shape\": [4]}, {\"data\": [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342], \"shape\": [6, 4]}, {\"data\": [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679], \"shape\": [4, 4]}, {\"data\": [-0.095243, 0.193295, -0.158108, -0.236503], \"shape\": [4]}]}, \"wrappers.Bidirectional.3\": {\"input\": {\"data\": [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829], \"shape\": [3, 6]}, \"expected\": {\"data\": [0.622907, 0.224597, -0.85085, -0.341647], \"shape\": [4]}, \"weights\": [{\"data\": [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397], \"shape\": [6, 4]}, {\"data\": [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973], \"shape\": [4, 4]}, {\"data\": [0.653857, -0.422921, -0.769865, 0.386656], \"shape\": [4]}, {\"data\": [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342], \"shape\": [6, 4]}, {\"data\": [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679], \"shape\": [4, 4]}, {\"data\": [-0.095243, 0.193295, -0.158108, -0.236503], \"shape\": [4]}]}, \"wrappers.Bidirectional.4\": {\"input\": {\"data\": [0.750054, 0.434148, -0.728844, 0.509119, -0.253407, -0.151866, 0.444465, 0.210897, -0.417866, -0.205582, -0.991291, 0.624873, 0.745016, -0.910733, -0.373436, -0.713311, 0.121669, 0.465829], \"shape\": [3, 6]}, \"expected\": {\"data\": [0.896581, -0.954891, -0.158707, 0.372146, 0.26347, 0.986305, -0.831838, 0.156544, 0.990187, -0.957637, -0.916605, -0.917549, 0.365499, 0.974113, -0.934135, -0.105309, 0.982344, -0.537111, -0.869863, -0.839838, -0.759049, 0.61521, -0.756189, 0.055226], \"shape\": [3, 8]}, \"weights\": [{\"data\": [0.971827, -0.898904, -0.987921, 0.529589, 0.043586, -0.541366, 0.316759, 0.351387, -0.292323, 0.445466, -0.922655, 0.437413, -0.483267, -0.478014, 0.7408, -0.595028, -0.718381, 0.349594, -0.091293, 0.14291, 0.633818, -0.686841, -0.925272, -0.740397], \"shape\": [6, 4]}, {\"data\": [0.180389, 0.629217, -0.656262, -0.476575, -0.36398, 0.987756, -0.579677, 0.883193, 0.651172, -0.820251, -0.64795, 0.857328, -0.4689, 0.356044, -0.641528, -0.531973], \"shape\": [4, 4]}, {\"data\": [0.653857, -0.422921, -0.769865, 0.386656], \"shape\": [4]}, {\"data\": [-0.838172, 0.91253, -0.538965, 0.880197, -0.347898, 0.009185, -0.43895, 0.943108, -0.237805, -0.726721, 0.52637, 0.292517, 0.593285, 0.936183, 0.733909, -0.412317, -0.367335, -0.984341, -0.494462, 0.525622, -0.455171, 0.79139, -0.101203, 0.528342], \"shape\": [6, 4]}, {\"data\": [-0.496602, 0.202253, 0.999106, 0.312228, -0.047113, 0.447672, -0.699984, -0.112078, -0.725913, 0.126383, 0.160941, -0.041802, -0.536565, -0.752919, 0.995063, 0.785679], \"shape\": [4, 4]}, {\"data\": [-0.095243, 0.193295, -0.158108, -0.236503], \"shape\": [4]}]}, \"wrappers.Bidirectional.5\": {\"input\": {\"data\": [0.579459, -0.589792, -0.267425, 0.603619, 0.96337, -0.768615, 0.684727, -0.085752, 0.631217, -0.536656, -0.354471, 0.293334, -0.840082, 0.990845, 0.28264, 0.692538, 0.965158, 0.451587], \"shape\": [3, 6]}, \"expected\": {\"data\": [0.594504, -0.714787, 0.058666, 0.362111, 0.113399, 0.386766, 0.769737, -0.644836, 0.43217, -0.360749, -0.335977, 0.33945, 0.728847, -0.092921, 0.368333, -0.71776, 0.602782, -0.557467, 0.453357, 0.247038, -0.276008, -0.447068, -0.092065, -0.617043], \"shape\": [3, 8]}, \"weights\": [{\"data\": [-0.400676, -0.806051, 0.727377, 0.299105, 0.162793, 0.696317, -0.630284, 0.653073, 0.242925, 0.148925, -0.187914, 0.351016, 0.546924, 0.075698, -0.743714, 0.635785, -0.867496, -0.475611, -0.836474, -0.099114, 0.730422, -0.75379, 0.737732, -0.042137, 0.648025, -0.050435, -0.231487, 0.332196, 0.529451, -0.350969, -0.287331, -0.108567, 0.290426, -0.498405, -0.986393, 0.140917, -0.18627, -0.278213, -0.28632, 0.342007, -0.711494, 0.26935, 0.769428, -0.817747, 0.65287, -0.242099, -0.155553, -0.463521, 0.019267, -0.511599, 0.208023, 0.140939, 0.609705, -0.970713, -0.812048, 0.603712, 0.440668, -0.967074, 0.876051, 0.675455, 0.333284, 0.618455, 0.468442, 0.671832, -0.605946, -0.917533, 0.270426, -0.426635, 0.341593, 0.837614, -0.175833, -0.465587], \"shape\": [6, 12]}, {\"data\": [-0.045344, -0.164038, -0.268339, 0.845397, -0.243892, 0.889969, -0.723107, -0.812532, -0.162915, 0.054766, 0.995428, 0.904954, -0.227887, -0.717716, 0.369742, 0.764909, 0.43452, -0.100535, 0.253479, 0.195278, 0.984495, -0.595437, 0.928364, -0.088226, -0.297404, -0.38593, 0.051969, -0.206956, 0.92133, -0.573615, 0.753414, -0.820892, 0.768965, 0.831183, -0.083506, -0.806636, -0.822986, -0.266864, -0.738629, 0.655838, -0.908376, -0.832082, 0.125397, 0.231704, -0.141658, 0.324014, 0.090288, -0.306376], \"shape\": [4, 12]}, {\"data\": [-0.034764, 0.373026, 0.5397, 0.050508, 0.828587, 0.724982, 0.888847, 0.267944, 0.976953, -0.776123, -0.387651, -0.192234], \"shape\": [12]}, {\"data\": [-0.48369, -0.447759, -0.566219, 0.343364, -0.24531, 0.701212, 0.035146, 0.441802, 0.667955, -0.504994, 0.666803, -0.831937, 0.197281, -0.417857, -0.39006, 0.86274, 0.715555, -0.617149, 0.333407, 0.642035, -0.919191, -0.828808, -0.477502, -0.727975, -0.999427, 0.0147, 0.861423, 0.587883, 0.980264, -0.295717, 0.048024, -0.025603, 0.062474, -0.54466, -0.593996, -0.515015, -0.17945, -0.035334, 0.418348, -0.276447, 0.911704, -0.965374, -0.912856, 0.559908, -0.423473, -0.554133, -0.319797, -0.849149, 0.969828, -0.634512, 0.268302, -0.737053, -0.538017, -0.480322, -0.361186, 0.318054, -0.852645, -0.519945, 0.499858, 0.073199, -0.093714, -0.172873, -0.927642, 0.042101, -0.419142, 0.922898, -0.709046, -0.454268, 0.884395, -0.725468, -0.50797, -0.683535], \"shape\": [6, 12]}, {\"data\": [-0.306533, -0.235389, -0.903843, -0.310018, -0.211702, -0.929241, -0.211704, -0.855145, 0.244396, 0.334903, 0.219381, 0.938061, -0.013659, 0.841669, 0.063987, -0.822806, -0.950197, 0.756071, 0.796209, 0.139445, -0.468052, 0.548326, 0.580119, -0.818757, -0.382378, -0.374014, 0.415244, -0.913233, -0.21266, 0.745815, -0.707557, 0.541733, -0.726652, 0.669064, -0.696091, 0.21855, 0.638637, -0.970069, 0.709007, 0.151012, -0.164932, -0.394785, 0.590232, -0.956107, 0.252234, 0.092064, 0.676041, 0.326743], \"shape\": [4, 12]}, {\"data\": [-0.064656, -0.046499, -0.690927, -0.559937, -0.676503, -0.827929, -0.488517, 0.039733, 0.473848, 0.938037, 0.999271, -0.961714], \"shape\": [12]}]}, \"wrappers.Bidirectional.6\": {\"input\": {\"data\": [-0.208593, -0.791925, 0.482012, -0.811503, 0.611931, -0.69639, -0.087624, 0.563664, -0.730199, 0.739224, 0.349534, 0.409244, -0.160169, 0.084091, -0.337315, -0.358966, 0.984383, -0.783392], \"shape\": [3, 6]}, \"expected\": {\"data\": [-0.09132, -0.320823, 0.063094, 0.294734, 0.009347, -0.075279, 0.13049, -0.391936, -0.092975, 0.049853, 0.054893, 0.027423, 0.423312, 0.05639, 0.280809, -0.298506, -0.19041, -0.11039, 0.294735, 0.26807, -0.152633, -0.041449, 0.127926, -0.285122], \"shape\": [3, 8]}, \"weights\": [{\"data\": [0.807118, -0.760589, -0.028865, -0.670325, -0.896482, -0.750147, 0.736501, 0.743636, 0.608933, 0.703828, 0.161015, 0.851966, -0.268783, -0.04837, 0.236778, -0.886123, 0.813034, -0.380336, -0.214975, -0.8337, -0.536234, 0.415819, -0.469715, -0.501354, -0.612303, 0.999023, -0.131152, -0.659838, -0.969144, 0.658844, -0.060329, -0.484303, -0.280648, 0.158796, 0.324335, -0.583718, 0.05907, 0.085148, -0.159317, 0.832273, 0.008118, -0.179334, -0.641468, 0.049695, -0.898869, 0.887157, 0.940259, -0.799015, -0.657864, 0.263749, -0.466117, 0.454708, -0.256237, 0.069986, -0.084429, 0.153432, 0.467724, 0.614946, 0.8988, 0.903929, -0.04614, 0.605232, 0.352153, -0.589127, -0.893261, 0.626536, 0.69489, 0.032637, -0.058497, -0.869516, -0.089778, 0.563949, 0.608511, -0.279182, 0.240354, 0.20926, 0.265094, 0.144285, 0.480487, 0.036267, -0.313521, -0.075342, 0.162992, 0.039256, 0.277475, -0.777398, 0.385225, 0.548992, 0.434589, -0.029444, -0.697455, -0.93891, -0.766289, -0.892662, -0.759472, 0.359897], \"shape\": [6, 16]}, {\"data\": [0.33535, -0.58156, -0.54846, 0.092896, -0.282469, -0.433627, 0.649036, -0.167267, 0.228306, -0.410728, 0.057924, 0.779121, 0.002282, -0.056874, 0.501906, 0.237949, 0.855971, 0.945186, 0.37607, -0.434584, 0.293534, 0.0914, -0.889186, 0.87441, 0.645452, -0.306185, -0.676605, 0.233388, -0.261631, -0.984845, 0.766819, -0.867325, -0.879335, 0.317177, -0.95397, -0.506246, -0.906304, -0.34783, 0.332394, -0.876325, 0.689498, 0.735502, -0.369079, 0.416847, -0.005394, -0.091598, -0.032022, 0.158824, -0.679499, -0.147576, -0.084029, 0.921847, -0.544815, -0.311653, -0.334702, 0.40131, -0.912162, 0.884366, -0.591035, -0.927795, 0.542396, -0.524613, -0.525259, 0.458834], \"shape\": [4, 16]}, {\"data\": [0.245776, 0.935485, 0.309313, 0.905204, 0.031089, 0.984402, 0.656903, -0.075944, -0.485436, -0.00131, 0.490612, 0.364067, -0.80787, -0.18118, -0.800993, 0.470466], \"shape\": [16]}, {\"data\": [0.608142, 0.031424, -0.113381, 0.761242, 0.350692, 0.55033, -0.465194, -0.192457, 0.472623, 0.115715, -0.887, 0.253264, -0.180434, -0.840145, -0.86505, -0.017223, 0.472874, 0.895249, 0.798031, 0.285864, 0.661202, 0.990973, 0.628736, 0.077497, -0.669397, -0.026501, 0.158669, -0.779973, 0.798492, 0.543891, 0.847622, -0.127898, -0.900805, 0.89186, 0.025119, -0.19005, -0.959915, 0.63755, -0.970897, 0.375914, -0.641188, -0.681191, 0.111849, -0.171632, -0.171887, -0.265957, 0.936405, 0.14059, 0.571594, -0.761868, 0.368138, -0.995003, -0.624834, 0.263911, -0.335803, 0.524822, 0.768229, 0.213674, 0.51678, 0.448993, -0.681158, 0.515448, -0.375105, 0.77563, 0.681558, -0.832669, 0.432138, -0.866504, -0.069609, -0.427233, -0.455544, -0.708099, -0.211247, -0.060945, -0.431296, -0.406991, 0.184405, -0.940906, -0.074347, 0.89056, 0.470936, -0.912834, -0.31047, 0.32027, 0.902325, 0.826502, 0.749141, 0.997955, 0.679228, 0.057812, -0.46663, 0.902338, 0.667435, -0.17336, 0.924087, 0.399279], \"shape\": [6, 16]}, {\"data\": [-0.274857, -0.894091, 0.79009, 0.858528, -0.618948, 0.516904, 0.970979, 0.394163, 0.477123, -0.25245, 0.562477, -0.85766, -0.854637, 0.57802, -0.819807, -0.218625, 0.325063, -0.543383, 0.260624, 0.339218, 0.197457, 0.313392, -0.757072, 0.463311, -0.595705, 0.333942, -0.86221, 0.346486, -0.358319, 0.612121, -0.891709, -0.751211, -0.940398, 0.833448, -0.113211, 0.425797, 0.8656, 0.1088, 0.788351, 0.078212, 0.280996, 0.890594, -0.670749, -0.157674, -0.097224, 0.28997, -0.887052, 0.952481, -0.883093, -0.212071, 0.302231, -0.581727, 0.877721, 0.10562, 0.268526, 0.335971, -0.048939, -0.442724, 0.058181, -0.647222, 0.655541, -0.710984, 0.162741, -0.91302], \"shape\": [4, 16]}, {\"data\": [0.074086, 0.934899, -0.863756, 0.656665, -0.286312, -0.850001, 0.249795, -0.610878, 0.523095, -0.399227, 0.840477, -0.834731, 0.878922, -0.914947, 0.646411, 0.568749], \"shape\": [16]}]}}\n"
     ]
    }
   ],
   "source": [
    "print(json.dumps(DATA))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [default]",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
